package org.macro.bench;

import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.Locale;
import java.util.logging.Level;
import java.util.logging.Logger;

public class RunPrettyFaceBenchmark {

    public static void main(String args[]) {
        int measurements;
        if (args.length > 0) {
            measurements = Integer.parseInt(args[0]);
        } else{
            throw new IllegalArgumentException("number runs missing!");
        }

        for (int measurement = 0; measurement < measurements; measurement++) {
            long ns = -System.nanoTime();

            int currentLocale = 0;
            Locale[] localeArray = {Locale.FRANCE, Locale.CHINA, Locale.GERMANY, Locale.ITALY};

                new Runner(localeArray[currentLocale++]);

                if (currentLocale == localeArray.length) {
                    currentLocale = 0;
                }
            

            ns += System.nanoTime();
            long totalTimeInMs = ns / 1000000;
            write(totalTimeInMs);
        }
    }

    private static void write(long totalTime) {
        PrintWriter printWriter = null;
        try {
            String fileName =
                    (System.getProperty("java.vm.vendor")
                    + System.getProperty("java.vm.name")
                    + System.getProperty("java.vm.info")
                    + System.getProperty("java.runtime.version")
                    + ".txt").replace(" ", "_");
            File resultFile = new File(fileName);
            printWriter = new PrintWriter(new FileWriter(resultFile, true));
            printWriter.println(totalTime);
        } catch (IOException ex) {
            Logger.getLogger(RunPrettyFaceBenchmark.class.getName()).log(Level.SEVERE, null, ex);
        } finally {
            printWriter.close();
        }
    }
}
